import requests
import redis
import random


def get_request_url():
    client = redis.Redis()
    url = client.lpop("request_url")
    url = url.decode()
    client.close()
    return url


def roeback(url):
    client = redis.Redis()
    client.lpush("request_url", url)
    client.close()


def main():
    for i in range(10):
        url = get_request_url()
        try:
            res = requests.get(url, timeout=1)
            print(res)
        except Exception as e:
            print(f"出错了，链接为{url}")
            roeback(url)
        stop = random.randint(1, 5)
        if stop == 3:
            break


if __name__ == "__main__":
    main()
